package cn.agiledata.bank.barcodepayment.form;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.SessionFactory;

import cn.agiledata.bank.common.dao.HqlPageListTemplate;
import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.StringUtil;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class BarCodeQueryPageList extends HqlPageListTemplate {
    private BarCodePayForm form;
    
    public BarCodeQueryPageList(BarCodePayForm form) {
        this.setSessionFactory((SessionFactory) IPBAppFactory.getObj("sessionFactory"));
        
        this.form = form;
    }

    public String getHql() {
        if (form == null) {
            String hql = " from BarCodePayDetail";
            return hql;
        }
        String hql = " from BarCodePayDetail a where 1=1 "; 
        if (form.getCode() != "")
            hql += " and a.barCode like :barCode";
        if (form.getCorpCode() !=null && form.getCorpCode() != "")
            hql += " and a.barCodePayCorp.code = :corpCode";
        if (form.getFromDate() != null)
            hql += " and :fromDate <= a.chargeDate and a.chargeDate < :toDate";
        if (form.getType().longValue() > 0)
            hql += " and a.barCodePayCorp.barCodePayType.id = :company";
        return hql;
    }

    public String getPageRecord() {
        return String.valueOf(Constant.PAGESIZE);
    }

    public Map getParams() {
        Map map = new HashMap();
        if (form == null) {
            return map;
        }
        if(!StringUtil.isStrEmpty(form.getCode())) {
            map.put("barCode","%"+form.getCode()+"%");
        }
        if(!StringUtil.isStrEmpty(form.getCorpCode())) {
            map.put("corpCode",form.getCorpCode());
        }
        if(form.getFromDate() != null) {
            map.put("fromDate",form.getFromDate());
        }
        if(form.getToDate() != null) {
            map.put("toDate",form.getToDate());
        }
        if(form.getType().longValue() > 0 ) {
            map.put("company",form.getType());
        }
        return map;
    }

    public String getStartPage() {
        if (form == null) {
            return "1";
        }
        return form.getStartPage();
    }
}
